import os
import rtconfig
from building import *

Import('SDK_LIB')

cwd = GetCurrentDir()
CPPDEFINES = ['__USE_XTL__']
# add general drivers
src = Split('''
board.c
''')

if GetDepend(['BSP_USING_ETH_W5500']):
    src += Glob('ports/w5500_device.c')

if GetDepend(['BSP_USING_U8G2_HWI2C']):
    src += Glob('ports/u8g2_i2c*.c')

if GetDepend(['BSP_USING_LED']):
    src += Glob('ports/led*.c')

src += Glob('ports/key*.c')


if GetDepend(['BSP_USING_SPI_FLASH']):
    src += Glob('ports/spi_flash_init.c')


if GetDepend(['BSP_USING_WDT']):
    src += Glob('wdt_feed.c')

path =  [cwd,cwd+"/ports"]

startup_path_prefix = SDK_LIB

if rtconfig.PLATFORM in ['gcc']:
    src += [startup_path_prefix + '/HAL_Driver/Startup/gcc/startup_gcc.s']
elif rtconfig.PLATFORM in ['armcc', 'armclang']:
    src += [startup_path_prefix + '/HAL_Driver/Startup/arm/startup_gcc.s']
elif rtconfig.PLATFORM in ['iccarm']:
    src += [startup_path_prefix + '/HAL_Driver/Startup/iar/startup_gcc.s']

group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)
Return('group')
